package com.leesche.zcsp.node.web.dao.aop;

import com.leesche.zcsp.node.web.dao.jdbc.impl.JdbcContextHolder;
import com.leesche.zcsp.node.web.service.impl.data.aop.redis.DeviceServiceAspect;
import org.apache.log4j.Logger;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * Created by Administrator on 2017-02-21.
 */
@Aspect
@Component
public class DataSourceRWSlaveAspect {
    public static final Logger LOGGER = Logger.getLogger(DeviceServiceAspect.class);

   /* @Pointcut("target(com.leesche.zcsp.node.web.dao.**) && (execution(* insert*(..)) || execution(* edit*(..)) || execution(* add*(..)) || execution(* update*(..)) || execution(* delete*(..)))")
    public void DDLAspect() {
        LOGGER.info("操作切入点......");
    }*/
/*
    @Pointcut("target(com.leesche.zcsp.node.web.service.*.*) && (execution(* select*(..)) || execution(* get*(..)) || execution(* find*(..)) )")
*/
   @Pointcut("execution(* com.leesche.zcsp.node.web.service.*.*find*(..))||execution(* com.leesche.zcsp.node.web.service.*.*select*(..))||execution(* com.leesche.zcsp.node.web.service.*.*get*(..))")
   public void DQLAspect() {
        LOGGER.info("查询切入点......");
    }

    @Before("DQLAspect() ")
    public void doBefore() {
        System.out.println("开始读取设置为读数据库");
        JdbcContextHolder.setSlave();
    }
    @After("DQLAspect()")
    public void doAfter() {
        System.out.println("读取完毕设置为读写数据源");
        JdbcContextHolder.setMaster();
    }




}
